﻿using AutoMapper;
using MediatR;
using SheepStorage.API.Application.Command;
using SheepStorage.API.Application.Command.EnterpriseCommand;
using SheepStorage.API.Baseclass;
using SheepStorage.Domain;
using SheepStorage.Domain.Entity;
using SheepStorage.Service.Interface;

namespace SheepStorage.API.Application.CommandHandlers.EnterpriseHandler
{
    //public class EnterpriseCreateCommandHandler : IRequestHandler<EnterpriseCreateCommand, int>
    public class EnterpriseCreateCommandHandler : IRequestHandler<EnterpriseCreateCommand, Results<int>>
    {
        private readonly IEnterpriseService enterpriseService;

        //private readonly SheepDbContext db;

        public EnterpriseCreateCommandHandler(IEnterpriseService enterpriseService)
        {
            this.enterpriseService = enterpriseService;

        }
        public async Task<Results<int>> Handle(EnterpriseCreateCommand request, CancellationToken cancellationToken)
        {
            //var enterprise = mapper.Map<Enterprise>(request);
            //var entity=await enterpriseService.Add(enterprise);
            //return Results<int>.DataResult(entity);
            var entity = new Enterprise
            {
                EnterpriseId = request.EnterpriseId,
                EnterpriseName = request.EnterpriseName,
                EnterpriseLogo = request.EnterpriseLogo,
                EnterpriseLabel = request.EnterpriseLabel,
                ProvinceId=request.ProvinceId,
                AreaId=request.AreaId,
                PlaceId = request.PlaceId,
                EnterprisePhone = request.EnterprisePhone,
                EnterpriseCode = request.EnterpriseCode,
                EnterpriseDesc = request.EnterpriseDesc,
                EnterpriseStop = request.EnterpriseStop,
                DutyPeople = request.DutyPeople,
                DutyMoney = request.DutyMoney,
                DutyManage = request.DutyManage,
                CheckPeople = request.CheckPeople,
                EnterpriseCount = request.EnterpriseCount,
            };
            var result = await enterpriseService.AddEnterprises(entity);
            return Results<int>.DataResult(result);
        }
    }
}
